package mt.comm;

import java.io.Serializable;

import mt.Order;
	/**
	 * Messages sent from clients to the server. A message contains a type (enum), the nickname of the sender (String), 
	 * and, depending on the message type, a new order. It has to be serializable so that it can go to the stream and be read on the server side.
	 * 
	 * @author Nuno Santos
	 *
	 */
public class ServerSide implements ServerSideMessage, Serializable{

		private static final long serialVersionUID = 23452;
		private String senderNickname;
		private Type type;
		private Order order = null;
		
		/**
		 * Creates a ServerSideMessage. A ServerSideMessage contains a type, the senders nickname and depending on the type an order.
		 * 
		 * @param type
		 * @param senderNickname
		 * @param order
		 */
		
		public ServerSide(Type type, String senderNickname, Order order){
			if(type == null || senderNickname == null)
				throw new IllegalArgumentException("The type and the sendersNickame can't be null.");
			
			this.type = type;
			
			if(type.equals(Type.NEW_ORDER));
				this.order = order;
				
			this.senderNickname = senderNickname;
		}
		
		/**
		 * Gets the type of the message.
		 * 
		 * @return type of the message.
		 */
		
		@Override
		public Type getType() {
			return type;
		}
		
		/**
		 * Gets the sender nickname.
		 * 
		 * @return sender's nickname.
		 */
		@Override
		public String getSenderNickname() {
			return senderNickname;
		}

		/**
		 * Gets the order in the message.
		 * 
		 * @return order.
		 */
		
		@Override
		public Order getOrder() {
			return order;
		}

	}

